package com.st.event.demo.source;

import com.st.event.demo.annotation.EventTrigger;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

public abstract class AbstractEventAnnotationSourceParser implements EventAnnotationSourceParser {

    protected final String TRIGGER_BEAN_NAME = "triggerBeanName";
    protected final String METHOD_NAME = "methodName";
    protected final String HANDLER_ENUM = "handler";

    private static final Class<? extends Annotation>[] ANNOTATION_CLASSES = new Class[]{EventTrigger.class};

    @Override
    public EventAttribute parsePayAnnotation(AnnotatedElement element) {
        System.out.println("执行10-----------");
        for (Class<? extends Annotation> clazz : ANNOTATION_CLASSES) {
            AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(element, clazz, false, false);
            if (attributes != null) {
                return parsePayAnnotation(attributes);
            }
        }
        return null;
    }

    protected abstract EventAttribute parsePayAnnotation(AnnotationAttributes attributes);
}
